import collections

import logging
import reprlib
import traceback
from functools import partial
from zlib import crc32

from datetime import date, datetime, time
import odoo.modules
from odoo.tools import pycompat
from ..models import MAGIC_COLUMNS, BaseModel
import odoo.tools as tools

NOT_OPERATOR = '!'
OR_OPERATOR = '|'
AND_OPERATOR = '&'
DOMAIN_OPERATORS = (NOT_OPERATOR, OR_OPERATOR, AND_OPERATOR)

TERM_OPERATORS = ('=', '!=', '<=', '<', '>', '>=', '=?', '=like', '=ilike',
                  'like', 'not like', 'ilike', 'not ilike', 'in', 'not in',
                  'child_of', 'parent_of')

NEGATIVE_TERM_OPERATORS = ('!=', 'not like', 'not ilike', 'not in')

DOMAIN_OPERATORS_NEGATION = {
    AND_OPERATOR: OR_OPERATOR,
    OR_OPERATOR: AND_OPERATOR,
}
TERM_OPERATORS_NEGATION = {
    '<': '>=',
    '>': '<=',
    '<=': '>',
    '>=': '<',
    '=': '!=',
    '!=': '=',
    'in': 'not in',
    'like': 'not like',
    'ilike': 'not ilike',
    'not in': 'in',
    'not like': 'like',
    'not ilike': 'ilike',
}

TRUE_LEAF = (1, '=', 1)
FALSE_LEAF = (0, '=', 1)

TRUE_DOMAIN = [TRUE_LEAF]
FALSE_DOMAIN = [FALSE_LEAF]

_logger = logging.getLogger(__name__)

def normalize_domain(domain):
    pass

def is_false(model, domain):
    pass

def combine(operator, unit, zero, domains):
    pass

def AND(domains):
    pass

def OR(domains):
    pass

def distribute_not(domain):
    pass

def _quote(to_quote):
    pass

def generate_table_alias(src_table_alias, joined_tables=[]):
    pass

def get_alias_from_query(from_query):
    pass

def normalize_leaf(element):
    pass

def is_operator(element):
    pass

def is_leaf(element, internal=False):
    pass

def select_from_where(cr, select_field, from_table, where_field, where_ids, where_operator):
    pass

def select_distinct_from_where_not_null(cr, select_field, from_table):
    pass

def get_unaccent_wrapper(cr):
    pass

class ExtendedLeaf(object):
    def __init__(self, leaf, model, join_context=None, internal=False):
        pass

    def __str__(self):
        pass

    def generate_alias(self):
        pass

    def add_join_context(self, model, lhs_col, table_col, link):
        pass

    def get_join_conditions(self):
        pass

    def get_tables(self):
        pass

    def _get_context_debug(self):
        pass

    def check_leaf(self, internal=False):
        pass

    def is_operator(self):
        pass

    def is_true_leaf(self):
        pass

    def is_false_leaf(self):
        pass

    def is_leaf(self, internal=False):
        pass

    def normalize_leaf(self):
        pass

def create_substitution_leaf(leaf, new_elements, new_model=None, internal=False):
    pass

class expression(object):
    def __init__(self, domain, model):
        pass

    def get_tables(self):
        pass

    def parse(self):
        pass

    def __leaf_to_sql(self, eleaf):
        pass

    def to_sql(self):
        pass